const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
// 解析jwt字符串
const { expressjwt }= require('express-jwt')
const app = express()
app.use(cors())
/* 编码处理 */
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extends: false }))

const secretkey = 'sakura-snows'
// 全局解析jwt，还原成为json 将数据挂载到req.user上去
app.use(expressjwt({ secret: secretkey,algorithms: ['HS256'],}).unless({ path: /\/user/ }))

/* 路由接口 */
const userInfo = require('./router/user')   // 用户接口
const wordInfo = require('./router/word')   // 单词接口
app.use('/user',userInfo)
app.use('/api', wordInfo)

app.listen(2303,()=>{ console.log('serve running')})